package com.quanfaqiang.demo1.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.quanfaqiang.demo1.mapper.OperateLogMapper;
import com.quanfaqiang.demo1.pojo.OperateLog;
import com.quanfaqiang.demo1.service.OperateLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

@Service
public class OperateLogServiceImpl implements OperateLogService {
    @Autowired
    private OperateLogMapper operateLogMapper;

    @Override
    public Page<OperateLog> selectAll(Integer currentPage, Integer pageSize) {
        Page<OperateLog> operateLogPage = new Page<>(currentPage,pageSize);
        QueryWrapper<OperateLog> objectQueryWrapper = new QueryWrapper<>();
        Page<OperateLog> operateLogPage1 = operateLogMapper.selectPage(operateLogPage, objectQueryWrapper);
        return operateLogPage1;
    }

    @Override
    public Page<OperateLog> serchTypeName(String operateUser, LocalDateTime startTime,LocalDateTime endTime, String operate, String operateName, Integer currentPage, Integer pageSize) {
        Page<OperateLog> page = new Page<>(currentPage, pageSize);
        QueryWrapper<OperateLog> noticeQueryWrapper = new QueryWrapper<>();
        if (operateUser != null && !"".equals(operateUser)) {
            noticeQueryWrapper.eq("operate_user", operateUser);
        }
        if (operate != null && !"".equals(operate)) {
            noticeQueryWrapper.eq("operate", operate);
        }
        if (operateName != null && !"".equals(operateName)) {
            noticeQueryWrapper.eq("operate_name", operateName);
        }
        if (startTime != null && !"".equals(startTime)) {
            noticeQueryWrapper.ge("operate_time", startTime);
        }
        if (endTime != null && !"".equals(endTime)) {
            noticeQueryWrapper.le("operate_time", endTime);
        }
        operateLogMapper.selectPage(page, noticeQueryWrapper);
        return page;
    }


    @Override
    public void delete(Integer id) {
        operateLogMapper.deleteById(id);
    }

    @Override
    public void deleteIds(List<Integer> ids) {
        operateLogMapper.deleteBatchIds(ids);
    }

    @Override
    public List<String> selectOperate() {
        ArrayList<String> strings = new ArrayList<>();
        QueryWrapper<OperateLog> queryWrapper = new QueryWrapper<>();
        List<OperateLog> operateLogs = operateLogMapper.selectList(queryWrapper);
        for (OperateLog operateLog : operateLogs) {
            strings.add(operateLog.getOperate());
        }

        return strings;
    }

    @Override
    public List<String> selectOperateName() {
        ArrayList<String> strings = new ArrayList<>();
        QueryWrapper<OperateLog> queryWrapper = new QueryWrapper<>();
        List<OperateLog> operateLogs = operateLogMapper.selectList(queryWrapper);
        for (OperateLog operateLog : operateLogs) {
            strings.add(operateLog.getOperateName());
        }
        return strings;
    }
}
